/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcnss.app.forms;

import com.rcnss.application.configuration.Configuration;
import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Form;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

/**
 *
 * @author Baligh GUESMI
 */
@SuppressWarnings("serial")
public class DatabaseDialog extends Window {
    
    private Configuration conf = new Configuration("","","","");
    private Form f = new Form();

    public DatabaseDialog() {
        this.setWidth("500px");
        this.setModal(true);
        this.setCaption("Data Base Configuration");

        Label t = new Label();
        this.conf.loadFromXML();

        BeanItem ConfBean = new BeanItem(this.conf);
        f.setItemDataSource(ConfBean);
        this.addComponent(f);

         Button close = new Button("Close", new Button.ClickListener() {
            // inline click-listener
            public void buttonClick(ClickEvent event) {
                // close the window by removing it from the parent window
                ((Window)getWindow().getParent()).removeWindow(getWindow());
            }
        });
        Button save = new Button("Save", new Button.ClickListener() {
            // inline click-listener
            public void buttonClick(ClickEvent event) {
                f.commit();
                if(conf.saveToXML())
                    ((Window)getWindow().getParent()).removeWindow(getWindow());
                else
                    getWindow().showNotification("Error", "We can not save informations", Window.Notification.TYPE_ERROR_MESSAGE);
            }
        });
        // The components added to the window are actually added to the window's
        // layout; you can use either. Alignments are set using the layout
        f.getFooter().addComponent(save);
        f.getFooter().addComponent(close);
        f.getFooter().setMargin(true, false, false, false);
    }
}
